<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</meta>
<title>日志查看</title>

<script type="text/javascript"
	src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript"
	src="http://cdn.bootcss.com/sockjs-client/1.1.1/sockjs.js"></script>
<script
	src="https://cdn.bootcss.com/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
	
	
	});

	function openSocket(url) {
		if ('WebSocket' in window) {
			websocket = new ReconnectingWebSocket(url);
		} else if ('MozWebSocket' in window) {
			websocket = new MozWebSocket(url);
		} else {
			websocket = new SockJS(url);
		}
		websocket.onmessage = onMessage;
	}
	
	function onMessage(evt) {
		var logContent = evt.data;
		if(logContent.indexOf("DEBUG")>=0){
			console.debug(logContent);
		}else if(logContent.indexOf("INFO")>=0){
			console.info(logContent);
		}else if(logContent.indexOf("WARN")>=0){
			console.warn(logContent);
		}else if(logContent.indexOf("ERROR")>=0){
			console.error(logContent);
		}
	}
	
	function doSend() {
		if (websocket.readyState == websocket.OPEN) {
			var msg = document.getElementById("inputMsg").value;
			websocket.send(msg); //调用后台handleTextMessage方法
			console.log("发送成功!");
		} else {
			console.log("连接失败!");
		}
	}
	
	function closeSocket() {
		console.log("关闭链接！");
		clearInterval(timer); 
		websocket.onclose();
	}

	window.Close = function() {
		closeSocket();
	}
	

	

	
</script>

</head>
<body>
	<button onclick="openSocket('ws://172.16.12.159:8080/websocket/log/xxxx')">开启日志</button>
	<button onclick="closeSocket()">关闭日志</button>
</body>
</html>